<template>
  <div class="rated">
    <p class="title">最受好评电影</p>
    <div class="wrapper">
      <ul>
        <li v-for="item in ratedList" :key="item._id">
          <div class="img-wrap">
            <img :src="item.imgUrl" alt="" />
            <div class="shadow" v-if="item.score">
              观众评分: {{ item.score }}
            </div>
            <div class="shadow" v-else>{{ item.wishNum }}人想看</div>
          </div>
          <p class="movie-title">{{ item.title }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
// 引入'better-scroll',用于做横向滚动
import BScroll from "better-scroll";
import { mapActions, mapState } from "vuex";

export default {
  // computed: mapState(["ratedList"]),
  // 默认只有state需要添加模块名，mututions，actions,getters都是注册在全局命名空间的，不需要加模块名
  // 如果使用模块化之后，state只能写成对象的形式了
  computed: mapState({
    ratedList: (state) => state.index.ratedList,
  }),
  async mounted() {
    await this.$store.dispatch("index/asyncGetData");
    // await this.asyncGetData();
    new BScroll(".wrapper", {
      startX: 0,
      scrollX: true,
      scrollY: false,
      click: true,
    });
  },
  methods: {
    // 如果有命名空间了，需要添加第一个参数是模块名称
    // ...mapActions("index", ["asyncGetData"]),
  },
};
</script>

<style lang="less" scoped>
.rated {
  width: 100%;
  height: 205px;
  background-color: #fff;
  padding: 12px 15px;

  .title {
    font-size: 14px;
    color: #333;
    margin: 0 0 12px;
  }

  .wrapper {
    overflow: hidden;
  }

  ul {
    // width: 100%;
    height: 150px;
    // 将这个元素转成有弹性盒效果的行内元素
    display: inline-flex;
    // display: inline;
    // overflow: auto;

    li {
      width: 85px;
      height: 100%;
      margin-right: 10px;
      flex-shrink: 0;

      .img-wrap {
        width: 85px;
        height: 110px;
        position: relative;

        img {
          width: 100%;
          height: 100%;
        }

        .shadow {
          position: absolute;
          width: 100%;
          height: 30px;
          background: linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.2),
            rgba(0, 0, 0, 0.8)
          );
          bottom: 0;
          left: 0;
          color: @score-color;
          font-size: @xs-font;
          line-height: 30px;
          font-weight: 900;
        }
      }

      .movie-title {
        font-size: @s-font;
        font-weight: 900;
        .ell();
        margin-top: 5px;
      }
    }
  }
}
</style>
